package com.huaru.message.xiancheng.B;

public class DemoThread implements Runnable{
    private int nike = 10;
    Object lock = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (lock){
                if(nike >0){
                    try {
                        Thread.sleep(1000);
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "抢到了第" + nike-- + "双鞋");
                }
            }
        }
    }
}
